/*
 * GSqliteConnectionPool.h
 *
 *  Created on: 2010-12-22
 *      Author: minhua
 */

#ifndef GSQLITECONNECTIONPOOL_H_
#define GSQLITECONNECTIONPOOL_H_

#include <QSqlDatabase>
#include <QList>
#include <QStringList>
#include <QMutex>

class GSqliteConnectionPool
{
// Member
private:
	QString _filename;
	QString _writeConnectionName;
	QMutex _writeMutex;
	QStringList _idleReadConnectionNameList;
	QStringList _busyReadConnectionNameList;
	QMutex _readMutex;
	int _readConnectionIndex;
	int _maxReadConnectionCount;


// Method
public:
	GSqliteConnectionPool(QString filename, int maxReadConnectionCount);
	virtual ~GSqliteConnectionPool();
	QSqlDatabase getReadConnection();
	QSqlDatabase getWriteConnection();
	void releaseConnection(QSqlDatabase connection);
};

#endif /* GSQLITECONNECTIONPOOL_H_ */
